<template>
    <a-layout style="min-height: 100vh">
    <a-layout-sider v-model:collapsed="collapsed" collapsible :theme="theme">
      <div class="logo" />
      <Menu :theme="theme" :collapsed="collapsed" @clickMenu="clickMenu"></Menu>
    </a-layout-sider>
    <a-layout>
      <a-layout-header style="background: #fff; padding: 0" >
        <slot v-if="collapsed">
          <menu-unfold-outlined class="trigger" @click="collapsed = !collapsed" />
        </slot>
        <slot v-else>
          <menu-fold-outlined class="trigger" @click="collapsed = !collapsed" />
        </slot>
        <Header :theme="theme" @changeTheme="changeTheme"></Header>
      </a-layout-header>
      <a-layout-content style="margin: 0 16px">
        <Breadcrumb :breadcrumbs="breadcrumbs" ></Breadcrumb>
        <div :style="{ padding: '24px', background: '#fff', minHeight: '95%' }">
          <router-view />
        </div>
      </a-layout-content>
      <Footer></Footer>
    </a-layout>
  </a-layout>
</template>

<script setup lang='ts'>
import { ref } from 'vue'
import Menu from './Menu.vue'
import Header from './Header.vue'
import Breadcrumb from './Breadcrumb.vue'
import Footer from './Footer.vue'
import { MenuFoldOutlined, MenuUnfoldOutlined } from '@ant-design/icons-vue'

// 主题
let themeLocal = localStorage.getItem('theme')
if (themeLocal === null) {
  themeLocal = 'dark'
}
// 菜单栏是否缩进
const collapsed = ref<boolean>(false)
// 面包屑数据
const breadcrumbs = ref<string[]>()
// 主题颜色
const theme = ref<string>(themeLocal)

// 接收头部子组件修改样式的方法
const changeTheme = (e: any): void => {
  theme.value = e
  localStorage.setItem('theme', theme.value)
}

// 接收菜单按钮点击事件，修改面包屑
const clickMenu = (e: string[]): void => {
  breadcrumbs.value = e
}

</script>

<style lang="scss">
.logo {
  height: 32px;
  margin: 16px;
  background: rgba(255, 255, 255, 0.3);
}

.site-layout .site-layout-background {
  background: #fff;
}
[data-theme='dark'] .site-layout .site-layout-background {
  background: #141414;
}

.trigger {
  font-size: 20px;
  padding: 0 20px;
  line-height: 64px;
}

.trigger:hover {
  background-color: #eeeeee;
}
</style>
